<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>src/core/codegenerator.cpp</title>
<link rel="stylesheet" type="text/css" href="highlight.css">
</head>
<body class="hl">
<pre class="hl"><span class="hl com">/***************************************************************************</span>
<span class="hl com">                          codegenerator.cpp  -  description</span>
<span class="hl com">                             -------------------</span>
<span class="hl com">    begin                : Die Jul 9 2002</span>
<span class="hl com">    copyright            : (C) 2002-2012 by Andre Simon</span>
<span class="hl com">    email                : andre.simon1&#64;gmx.de</span>
<span class="hl com"> ***************************************************************************/</span>


<span class="hl com">/*</span>
<span class="hl com">This file is part of Highlight.</span>
<span class="hl com"></span>
<span class="hl com">Highlight is free software: you can redistribute it and/or modify</span>
<span class="hl com">it under the terms of the GNU General Public License as published by</span>
<span class="hl com">the Free Software Foundation, either version 3 of the License, or</span>
<span class="hl com">(at your option) any later version.</span>
<span class="hl com"></span>
<span class="hl com">Highlight is distributed in the hope that it will be useful,</span>
<span class="hl com">but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="hl com">MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="hl com">GNU General Public License for more details.</span>
<span class="hl com"></span>
<span class="hl com">You should have received a copy of the GNU General Public License</span>
<span class="hl com">along with Highlight.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="hl com">*/</span>


<span class="hl ppc">#include &lt;climits&gt;</span>
<span class="hl ppc">#include &lt;memory&gt;</span>
<span class="hl ppc">#include &lt;boost/xpressive/xpressive_dynamic.hpp&gt;</span>

<span class="hl ppc">#include</span> <span class="hl pps">&quot;codegenerator.h&quot;</span><span class="hl ppc"></span>

<span class="hl ppc">#include</span> <span class="hl pps">&quot;htmlgenerator.h&quot;</span><span class="hl ppc"></span>
<span class="hl ppc">#include</span> <span class="hl pps">&quot;xhtmlgenerator.h&quot;</span><span class="hl ppc"></span>
<span class="hl ppc">#include</span> <span class="hl pps">&quot;rtfgenerator.h&quot;</span><span class="hl ppc"></span>
<span class="hl ppc">#include</span> <span class="hl pps">&quot;latexgenerator.h&quot;</span><span class="hl ppc"></span>
<span class="hl ppc">#include</span> <span class="hl pps">&quot;texgenerator.h&quot;</span><span class="hl ppc"></span>
<span class="hl ppc">#include</span> <span class="hl pps">&quot;svggenerator.h&quot;</span><span class="hl ppc"></span>
<span class="hl ppc">#include</span> <span class="hl pps">&quot;bbcodegenerator.h&quot;</span><span class="hl ppc"></span>
<span class="hl ppc">#include</span> <span class="hl pps">&quot;pangogenerator.h&quot;</span><span class="hl ppc"></span>
<span class="hl ppc">#include</span> <span class="hl pps">&quot;odtgenerator.h&quot;</span><span class="hl ppc"></span>
<span class="hl ppc">#include</span> <span class="hl pps">&quot;astyle/astyle.h&quot;</span><span class="hl ppc"></span>
<span class="hl ppc">#include</span> <span class="hl pps">&quot;astyle/ASStreamIterator.h&quot;</span><span class="hl ppc"></span>
<span class="hl ppc">#include</span> <span class="hl pps">&quot;mygenerator.h&quot;</span><span class="hl ppc"></span>

<span class="hl ppc">#if !defined (QT)</span>
<span class="hl ppc">#include</span> <span class="hl pps">&quot;ansigenerator.h&quot;</span><span class="hl ppc"></span>
<span class="hl ppc">#include</span> <span class="hl pps">&quot;xterm256generator.h&quot;</span><span class="hl ppc"></span>
<span class="hl ppc">#endif</span>

<span class="hl kwa">using namespace</span> std<span class="hl opt">;</span>

<span class="hl kwa">namespace</span> highlight
<span class="hl opt">{</span>
<span class="hl kwb">const unsigned int</span> CodeGenerator<span class="hl opt">::</span>NUMBER_BUILTIN_STATES <span class="hl opt">=</span> highlight<span class="hl opt">::</span>KEYWORD<span class="hl opt">;</span>

<span class="hl kwb">const</span> string CodeGenerator<span class="hl opt">::</span>STY_NAME_STD<span class="hl opt">=</span><span class="hl str">&quot;std&quot;</span><span class="hl opt">;</span>
<span class="hl kwb">const</span> string CodeGenerator<span class="hl opt">::</span>STY_NAME_STR<span class="hl opt">=</span><span class="hl str">&quot;str&quot;</span><span class="hl opt">;</span>
<span class="hl kwb">const</span> string CodeGenerator<span class="hl opt">::</span>STY_NAME_NUM<span class="hl opt">=</span><span class="hl str">&quot;num&quot;</span><span class="hl opt">;</span>
<span class="hl kwb">const</span> string CodeGenerator<span class="hl opt">::</span>STY_NAME_SLC<span class="hl opt">=</span><span class="hl str">&quot;slc&quot;</span><span class="hl opt">;</span>
<span class="hl kwb">const</span> string CodeGenerator<span class="hl opt">::</span>STY_NAME_COM<span class="hl opt">=</span><span class="hl str">&quot;com&quot;</span><span class="hl opt">;</span>
<span class="hl kwb">const</span> string CodeGenerator<span class="hl opt">::</span>STY_NAME_ESC<span class="hl opt">=</span><span class="hl str">&quot;esc&quot;</span><span class="hl opt">;</span>
<span class="hl kwb">const</span> string CodeGenerator<span class="hl opt">::</span>STY_NAME_DIR<span class="hl opt">=</span><span class="hl str">&quot;ppc&quot;</span><span class="hl opt">;</span> <span class="hl slc">//preprocessor</span>
<span class="hl kwb">const</span> string CodeGenerator<span class="hl opt">::</span>STY_NAME_DST<span class="hl opt">=</span><span class="hl str">&quot;pps&quot;</span><span class="hl opt">;</span> <span class="hl slc">//preprocessor string</span>
<span class="hl kwb">const</span> string CodeGenerator<span class="hl opt">::</span>STY_NAME_LIN<span class="hl opt">=</span><span class="hl str">&quot;lin&quot;</span><span class="hl opt">;</span>
<span class="hl kwb">const</span> string CodeGenerator<span class="hl opt">::</span>STY_NAME_SYM<span class="hl opt">=</span><span class="hl str">&quot;opt&quot;</span><span class="hl opt">;</span> <span class="hl slc">//operator</span>
<span class="hl kwb">const</span> string CodeGenerator<span class="hl opt">::</span>STY_NAME_IPL<span class="hl opt">=</span><span class="hl str">&quot;ipl&quot;</span><span class="hl opt">;</span> <span class="hl slc">//interpolation</span>

CodeGenerator <span class="hl opt">*</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">getInstance</span> <span class="hl opt">(</span> OutputType type <span class="hl opt">)</span>
<span class="hl opt">{</span>
    CodeGenerator<span class="hl opt">*</span> generator<span class="hl opt">=</span>NULL<span class="hl opt">;</span>
    <span class="hl kwa">switch</span> <span class="hl opt">(</span> type <span class="hl opt">)</span>
    <span class="hl opt">{</span>
    <span class="hl kwa">case</span> HTML<span class="hl opt">:</span>
        generator <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">HtmlGenerator</span><span class="hl opt">();</span>
        <span class="hl kwa">break</span><span class="hl opt">;</span>
    <span class="hl kwa">case</span> XHTML<span class="hl opt">:</span>
        generator <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">XHtmlGenerator</span><span class="hl opt">();</span>
        <span class="hl kwa">break</span><span class="hl opt">;</span>
    <span class="hl kwa">case</span> TEX<span class="hl opt">:</span>
        generator <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">TexGenerator</span> <span class="hl opt">();</span>
        <span class="hl kwa">break</span><span class="hl opt">;</span>
    <span class="hl kwa">case</span> LATEX<span class="hl opt">:</span>
        generator <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">LatexGenerator</span><span class="hl opt">();</span>
        <span class="hl kwa">break</span><span class="hl opt">;</span>
    <span class="hl kwa">case</span> RTF<span class="hl opt">:</span>
        generator <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">RtfGenerator</span> <span class="hl opt">();</span>
        <span class="hl kwa">break</span><span class="hl opt">;</span>
    <span class="hl kwa">case</span> SVG<span class="hl opt">:</span>
        generator <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">SVGGenerator</span><span class="hl opt">();</span>
        <span class="hl kwa">break</span><span class="hl opt">;</span>
    <span class="hl kwa">case</span> BBCODE<span class="hl opt">:</span>
        generator <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">BBCodeGenerator</span><span class="hl opt">();</span>
        <span class="hl kwa">break</span><span class="hl opt">;</span>
    <span class="hl kwa">case</span> PANGO<span class="hl opt">:</span>
        generator <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">PangoGenerator</span><span class="hl opt">();</span>
        <span class="hl kwa">break</span><span class="hl opt">;</span>
    <span class="hl kwa">case</span> ODTFLAT<span class="hl opt">:</span>
        generator <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">ODTGenerator</span><span class="hl opt">();</span>
        <span class="hl kwa">break</span><span class="hl opt">;</span>
<span class="hl ppc">#if !defined (QT)</span>
    <span class="hl kwa">case</span> ANSI<span class="hl opt">:</span>
        generator <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">AnsiGenerator</span><span class="hl opt">();</span>
        <span class="hl kwa">break</span><span class="hl opt">;</span>
    <span class="hl kwa">case</span> XTERM256<span class="hl opt">:</span>
        generator <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">Xterm256Generator</span><span class="hl opt">();</span>
        <span class="hl kwa">break</span><span class="hl opt">;</span>
    <span class="hl kwa">case</span> MY<span class="hl opt">:</span>
        generator <span class="hl opt">=</span> <span class="hl kwa">new</span> <span class="hl kwd">MyGenerator</span><span class="hl opt">();</span>
        <span class="hl kwa">break</span><span class="hl opt">;</span>
<span class="hl ppc">#endif</span>
    <span class="hl kwa">default</span><span class="hl opt">:</span>
        <span class="hl kwa">break</span><span class="hl opt">;</span>
    <span class="hl opt">}</span>
    <span class="hl kwa">return</span> generator<span class="hl opt">;</span>
<span class="hl opt">}</span>


CodeGenerator<span class="hl opt">::</span><span class="hl kwd">CodeGenerator</span> <span class="hl opt">(</span> highlight<span class="hl opt">::</span>OutputType type <span class="hl opt">)</span>
    <span class="hl opt">:</span><span class="hl kwd">currentSyntax</span><span class="hl opt">(</span>NULL<span class="hl opt">),</span>
     <span class="hl kwd">in</span> <span class="hl opt">(</span> NULL <span class="hl opt">),</span>
     <span class="hl kwd">out</span> <span class="hl opt">(</span> NULL <span class="hl opt">),</span>
     <span class="hl kwd">encoding</span> <span class="hl opt">(</span> <span class="hl str">&quot;none&quot;</span> <span class="hl opt">),</span>
     <span class="hl kwd">docTitle</span> <span class="hl opt">(</span> <span class="hl str">&quot;Source file&quot;</span> <span class="hl opt">),</span>
     <span class="hl kwd">maskWs</span> <span class="hl opt">(</span> <span class="hl kwa">false</span> <span class="hl opt">),</span>
     <span class="hl kwd">excludeWs</span> <span class="hl opt">(</span> <span class="hl kwa">false</span> <span class="hl opt">),</span>
     <span class="hl kwd">fragmentOutput</span> <span class="hl opt">(</span> <span class="hl kwa">false</span> <span class="hl opt">),</span>
     <span class="hl kwd">showLineNumbers</span> <span class="hl opt">(</span> <span class="hl kwa">false</span> <span class="hl opt">),</span>
     <span class="hl kwd">lineNumberFillZeroes</span> <span class="hl opt">(</span> <span class="hl kwa">false</span> <span class="hl opt">),</span>
     <span class="hl kwd">printNewLines</span><span class="hl opt">(</span><span class="hl kwa">true</span><span class="hl opt">),</span>
     <span class="hl kwd">baseFontSize</span><span class="hl opt">(</span><span class="hl str">&quot;10&quot;</span><span class="hl opt">),</span>
     <span class="hl kwd">lineNumber</span> <span class="hl opt">(</span> <span class="hl num">0</span> <span class="hl opt">),</span>
     <span class="hl kwd">lineNumberOffset</span> <span class="hl opt">(</span> <span class="hl num">0</span> <span class="hl opt">),</span>
     <span class="hl kwd">includeStyleDef</span> <span class="hl opt">(</span> <span class="hl kwa">false</span> <span class="hl opt">),</span>
     <span class="hl kwd">lineIndex</span> <span class="hl opt">(</span> <span class="hl num">0</span> <span class="hl opt">),</span>
     <span class="hl kwd">lineNumberWidth</span> <span class="hl opt">(</span> <span class="hl num">5</span> <span class="hl opt">),</span>
     <span class="hl kwd">maxLineCnt</span> <span class="hl opt">(</span> UINT_MAX <span class="hl opt">),</span>
     <span class="hl kwd">terminatingChar</span> <span class="hl opt">(</span> <span class="hl str">'\0'</span> <span class="hl opt">),</span>
     <span class="hl kwd">formatter</span> <span class="hl opt">(</span> NULL <span class="hl opt">),</span>
     <span class="hl kwd">formattingEnabled</span> <span class="hl opt">(</span> <span class="hl kwa">false</span> <span class="hl opt">),</span>
     <span class="hl kwd">formattingPossible</span> <span class="hl opt">(</span> <span class="hl kwa">false</span> <span class="hl opt">),</span>
     <span class="hl kwd">validateInput</span> <span class="hl opt">(</span> <span class="hl kwa">false</span> <span class="hl opt">),</span>
     <span class="hl kwd">numberWrappedLines</span> <span class="hl opt">(</span> <span class="hl kwa">true</span> <span class="hl opt">),</span>	<span class="hl slc">//until now, wrapped lines were always numbered, so this remains the default.</span>
     <span class="hl kwd">noTrailingNewLine</span><span class="hl opt">(</span><span class="hl kwa">false</span><span class="hl opt">),</span>
     <span class="hl kwd">resultOfHook</span><span class="hl opt">(</span><span class="hl kwa">false</span><span class="hl opt">),</span>
     <span class="hl kwd">keywordCase</span> <span class="hl opt">(</span> StringTools<span class="hl opt">::</span>CASE_UNCHANGED <span class="hl opt">),</span>
     <span class="hl kwd">eolDelimiter</span> <span class="hl opt">(</span><span class="hl str">'</span><span class="hl esc">\n</span><span class="hl str">'</span><span class="hl opt">),</span>
     <span class="hl kwd">outputType</span> <span class="hl opt">(</span> type <span class="hl opt">)</span>
<span class="hl opt">{</span>
<span class="hl opt">}</span>


CodeGenerator<span class="hl opt">::~</span><span class="hl kwd">CodeGenerator</span><span class="hl opt">()</span>
<span class="hl opt">{</span>
    <span class="hl kwa">delete</span> formatter<span class="hl opt">;</span>

    <span class="hl kwa">for</span> <span class="hl opt">(</span> map<span class="hl opt">&lt;</span>string<span class="hl opt">,</span> SyntaxReader<span class="hl opt">*&gt;::</span>iterator it<span class="hl opt">=</span>syntaxReaders<span class="hl opt">.</span><span class="hl kwd">begin</span><span class="hl opt">();</span> it<span class="hl opt">!=</span>syntaxReaders<span class="hl opt">.</span><span class="hl kwd">end</span><span class="hl opt">();</span> it<span class="hl opt">++ ) {</span>
        <span class="hl kwa">delete</span> it<span class="hl opt">-&gt;</span>second<span class="hl opt">;</span>
    <span class="hl opt">}</span>
<span class="hl opt">}</span>


<span class="hl kwb">bool</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">initTheme</span> <span class="hl opt">(</span> <span class="hl kwb">const</span> string<span class="hl opt">&amp;</span> themePath <span class="hl opt">)</span>
<span class="hl opt">{</span>
    <span class="hl kwa">this</span><span class="hl opt">-&gt;</span>themePath<span class="hl opt">=</span>themePath<span class="hl opt">;</span>
    <span class="hl kwb">bool</span> loadOK <span class="hl opt">=</span> docStyle<span class="hl opt">.</span><span class="hl kwd">load</span> <span class="hl opt">(</span> themePath<span class="hl opt">,</span> outputType <span class="hl opt">);</span>
    <span class="hl kwd">initOutputTags</span><span class="hl opt">();</span>
    <span class="hl kwa">return</span> loadOK<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">const</span> string<span class="hl opt">&amp;</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">getStyleName</span><span class="hl opt">()</span>
<span class="hl opt">{</span>
    <span class="hl kwa">return</span> themePath<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setLineNumberWidth</span> <span class="hl opt">(</span> <span class="hl kwb">int</span> w <span class="hl opt">)</span>
<span class="hl opt">{</span>
    lineNumberWidth<span class="hl opt">=</span>w<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">int</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">getLineNumberWidth</span><span class="hl opt">()</span>
<span class="hl opt">{</span>
    <span class="hl kwa">return</span> lineNumberWidth<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setPrintLineNumbers</span> <span class="hl opt">(</span> <span class="hl kwb">bool</span> flag<span class="hl opt">,</span> <span class="hl kwb">unsigned int</span> startCnt <span class="hl opt">)</span>
<span class="hl opt">{</span>
    showLineNumbers<span class="hl opt">=</span>flag<span class="hl opt">;</span>
    lineNumberOffset <span class="hl opt">=</span> startCnt<span class="hl opt">-</span><span class="hl num">1</span><span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">bool</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">getPrintLineNumbers</span><span class="hl opt">()</span>
<span class="hl opt">{</span>
    <span class="hl kwa">return</span> showLineNumbers<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setPrintZeroes</span> <span class="hl opt">(</span> <span class="hl kwb">bool</span> flag <span class="hl opt">)</span>
<span class="hl opt">{</span>
    lineNumberFillZeroes<span class="hl opt">=</span>flag<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">bool</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">getPrintZeroes</span><span class="hl opt">()</span>
<span class="hl opt">{</span>
    <span class="hl kwa">return</span> lineNumberFillZeroes<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setIncludeStyle</span> <span class="hl opt">(</span> <span class="hl kwb">bool</span> flag <span class="hl opt">)</span>
<span class="hl opt">{</span>
    includeStyleDef <span class="hl opt">=</span> flag<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">disableTrailingNL</span> <span class="hl opt">(</span> <span class="hl kwb">bool</span> flag <span class="hl opt">)</span>
<span class="hl opt">{</span>
    noTrailingNewLine <span class="hl opt">=</span> flag<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setStyleInputPath</span> <span class="hl opt">(</span> <span class="hl kwb">const</span> string<span class="hl opt">&amp;</span> path <span class="hl opt">)</span>
<span class="hl opt">{</span>
    styleInputPath <span class="hl opt">=</span> path<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setStyleOutputPath</span> <span class="hl opt">(</span> <span class="hl kwb">const</span> string<span class="hl opt">&amp;</span> path <span class="hl opt">)</span>
<span class="hl opt">{</span>
    styleOutputPath <span class="hl opt">=</span> path<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setPluginReadFile</span> <span class="hl opt">(</span> <span class="hl kwb">const</span> string<span class="hl opt">&amp;</span> path <span class="hl opt">)</span>
<span class="hl opt">{</span>
    pluginReadFile <span class="hl opt">=</span> path<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">const</span> string<span class="hl opt">&amp;</span>  CodeGenerator<span class="hl opt">::</span><span class="hl kwd">getStyleInputPath</span><span class="hl opt">()</span>
<span class="hl opt">{</span>
    <span class="hl kwa">return</span> styleInputPath<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">const</span> string<span class="hl opt">&amp;</span>  CodeGenerator<span class="hl opt">::</span><span class="hl kwd">getStyleOutputPath</span><span class="hl opt">()</span>
<span class="hl opt">{</span>
    <span class="hl kwa">return</span> styleOutputPath<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setFragmentCode</span> <span class="hl opt">(</span> <span class="hl kwb">bool</span> flag <span class="hl opt">)</span>
<span class="hl opt">{</span>
    fragmentOutput<span class="hl opt">=</span>flag<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">bool</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">getFragmentCode</span><span class="hl opt">()</span>
<span class="hl opt">{</span>
    <span class="hl kwa">return</span> fragmentOutput<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setValidateInput</span> <span class="hl opt">(</span> <span class="hl kwb">bool</span> flag <span class="hl opt">)</span>
<span class="hl opt">{</span>
    validateInput<span class="hl opt">=</span>flag<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">bool</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">getValidateInput</span><span class="hl opt">()</span>
<span class="hl opt">{</span>
    <span class="hl kwa">return</span> validateInput<span class="hl opt">;</span>
<span class="hl opt">}</span>


<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setNumberWrappedLines</span> <span class="hl opt">(</span> <span class="hl kwb">bool</span> flag <span class="hl opt">)</span>
<span class="hl opt">{</span>
    numberWrappedLines<span class="hl opt">=</span>flag<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">bool</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">getNumberWrappedLines</span><span class="hl opt">() {</span>
    <span class="hl kwa">return</span> numberWrappedLines<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setBaseFont</span> <span class="hl opt">(</span> <span class="hl kwb">const</span> string<span class="hl opt">&amp;</span> s <span class="hl opt">)</span>
<span class="hl opt">{</span>
    baseFont <span class="hl opt">=</span> s<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setBaseFontSize</span> <span class="hl opt">(</span> <span class="hl kwb">const</span> string<span class="hl opt">&amp;</span> s <span class="hl opt">)</span>
<span class="hl opt">{</span>
    baseFontSize <span class="hl opt">=</span> s <span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setStartingNestedLang</span><span class="hl opt">(</span><span class="hl kwb">const</span> string <span class="hl opt">&amp;</span>langName<span class="hl opt">) {</span>
    embedLangStart <span class="hl opt">=</span> langName<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">const</span> string CodeGenerator<span class="hl opt">::</span><span class="hl kwd">getBaseFont</span><span class="hl opt">()</span> <span class="hl kwb">const</span>
<span class="hl opt">{</span>
    <span class="hl kwa">if</span> <span class="hl opt">( !</span>baseFont<span class="hl opt">.</span><span class="hl kwd">empty</span><span class="hl opt">() )</span> <span class="hl kwa">return</span> baseFont<span class="hl opt">;</span>
    <span class="hl kwa">switch</span> <span class="hl opt">(</span> outputType <span class="hl opt">)</span>
    <span class="hl opt">{</span>
    <span class="hl kwa">case</span> HTML<span class="hl opt">:</span>
    <span class="hl kwa">case</span> XHTML<span class="hl opt">:</span>
        <span class="hl kwa">return</span> <span class="hl str">&quot;'Courier New',monospace&quot;</span><span class="hl opt">;</span>
        <span class="hl kwa">break</span><span class="hl opt">;</span>
    <span class="hl kwa">case</span> LATEX<span class="hl opt">:</span>
        <span class="hl kwa">return</span> <span class="hl str">&quot;ttfamily&quot;</span><span class="hl opt">;</span>
        <span class="hl kwa">break</span><span class="hl opt">;</span>
    <span class="hl kwa">case</span> TEX<span class="hl opt">:</span>
        <span class="hl kwa">return</span> <span class="hl str">&quot;tt&quot;</span><span class="hl opt">;</span>
        <span class="hl kwa">break</span><span class="hl opt">;</span>
    <span class="hl kwa">case</span> ODTFLAT<span class="hl opt">:</span>
        <span class="hl kwa">return</span> <span class="hl str">&quot;FreeMono&quot;</span><span class="hl opt">;</span>
        <span class="hl kwa">break</span><span class="hl opt">;</span>
    <span class="hl kwa">default</span><span class="hl opt">:</span>
        <span class="hl kwa">return</span> <span class="hl str">&quot;Courier New&quot;</span><span class="hl opt">;</span>
    <span class="hl opt">}</span>
<span class="hl opt">}</span>

<span class="hl kwb">const</span> string CodeGenerator<span class="hl opt">::</span><span class="hl kwd">getBaseFontSize</span><span class="hl opt">()</span>
<span class="hl opt">{</span>
    <span class="hl kwa">return</span> baseFontSize<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setTitle</span> <span class="hl opt">(</span> <span class="hl kwb">const</span> string <span class="hl opt">&amp;</span> title <span class="hl opt">)</span>
<span class="hl opt">{</span>
    <span class="hl kwa">if</span> <span class="hl opt">( !</span>title<span class="hl opt">.</span><span class="hl kwd">empty</span><span class="hl opt">() )</span> docTitle<span class="hl opt">=</span> title<span class="hl opt">;</span>
<span class="hl opt">}</span>

string CodeGenerator<span class="hl opt">::</span><span class="hl kwd">getTitle</span><span class="hl opt">()</span>
<span class="hl opt">{</span>
    <span class="hl kwa">return</span> docTitle<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setEncoding</span> <span class="hl opt">(</span> <span class="hl kwb">const</span> string<span class="hl opt">&amp;</span> encodingName <span class="hl opt">)</span>
<span class="hl opt">{</span>
    encoding <span class="hl opt">=</span> encodingName<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">bool</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">formattingDisabled</span><span class="hl opt">()</span>
<span class="hl opt">{</span>
    <span class="hl kwa">return</span> <span class="hl opt">!</span>formattingEnabled<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setMaxInputLineCnt</span> <span class="hl opt">(</span> <span class="hl kwb">unsigned int</span> cnt <span class="hl opt">)</span>
<span class="hl opt">{</span>
    maxLineCnt <span class="hl opt">=</span> cnt<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">bool</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">formattingIsPossible</span><span class="hl opt">()</span>
<span class="hl opt">{</span>
    <span class="hl kwa">return</span> formattingPossible<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setPreformatting</span> <span class="hl opt">(</span> WrapMode lineWrappingStyle<span class="hl opt">,</span>
                                       <span class="hl kwb">unsigned int</span> lineLength<span class="hl opt">,</span>
                                       <span class="hl kwb">int</span> numberSpaces <span class="hl opt">)</span>
<span class="hl opt">{</span>
    <span class="hl kwb">bool</span> enableWrap <span class="hl opt">=</span> lineWrappingStyle<span class="hl opt">!=</span>WRAP_DISABLED<span class="hl opt">;</span>
    <span class="hl kwb">bool</span> replaceTabs <span class="hl opt">=</span> numberSpaces <span class="hl opt">&gt;</span> <span class="hl num">0</span><span class="hl opt">;</span>

    <span class="hl kwa">if</span> <span class="hl opt">(</span> enableWrap <span class="hl opt">||</span> replaceTabs <span class="hl opt">)</span>
    <span class="hl opt">{</span>
        preFormatter<span class="hl opt">.</span><span class="hl kwd">setWrap</span> <span class="hl opt">(</span> enableWrap <span class="hl opt">);</span>
        preFormatter<span class="hl opt">.</span><span class="hl kwd">setWrapIndentBraces</span> <span class="hl opt">(</span> lineWrappingStyle<span class="hl opt">==</span>WRAP_DEFAULT <span class="hl opt">);</span>
        preFormatter<span class="hl opt">.</span><span class="hl kwd">setWrapLineLength</span> <span class="hl opt">(</span> lineLength <span class="hl opt">);</span>
        preFormatter<span class="hl opt">.</span><span class="hl kwd">setReplaceTabs</span> <span class="hl opt">(</span> replaceTabs <span class="hl opt">);</span>
        preFormatter<span class="hl opt">.</span><span class="hl kwd">setNumberSpaces</span> <span class="hl opt">(</span> numberSpaces <span class="hl opt">);</span>
    <span class="hl opt">}</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setKeyWordCase</span> <span class="hl opt">(</span> StringTools<span class="hl opt">::</span>KeywordCase keyCase <span class="hl opt">)</span>
<span class="hl opt">{</span>
    keywordCase <span class="hl opt">=</span> keyCase<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">setEOLDelimiter</span><span class="hl opt">(</span><span class="hl kwb">char</span> delim<span class="hl opt">) {</span>
    eolDelimiter <span class="hl opt">=</span> delim<span class="hl opt">;</span>
<span class="hl opt">}</span>

<span class="hl kwb">void</span> CodeGenerator<span class="hl opt">::</span><span class="hl kwd">reset</span><span class="hl opt">()</span>
<span class="hl opt">{</span>
    lineIndex <span class="hl opt">=</span> <span class="hl num">0</span><span class="hl opt">;</span>
    lineNumber <span class="hl opt">=</span> <span class="hl num">0</span><span class="hl opt">;</span>
    line<span class="hl opt">.</span><span class="hl kwd">clear</span><span class="hl opt">();</span>
    preFormatter<span class="hl opt">.</span><span class="hl kwd">reset</span><span class="hl opt">();</span>
    inFile<span class="hl opt">.</span><span class="hl kwd">clear</span><span class="hl opt">();</span>
    outFile<span class="hl opt">.</span><span class="hl kwd">clear</span><span class="hl opt">();</span>
    hostLangDefPath<span class="hl opt">.</span><span class="hl kwd">clear</span><span class="hl opt">();</span>
    embedLangDefPath<span class="hl opt">.</span><span class="hl kwd">clear</span><span class="hl opt">();</span>
    printNewLines<span class="hl opt">=</span><span class="hl kwa">true</span><span class="hl opt">;</span>
<span class="hl opt">}</span>

</pre>
</body>
</html>
<!--HTML generated by highlight 3.23, http://www.andre-simon.de/-->
